package com.fanqiechaodan.proxy.jdkproxy;

import com.fanqiechaodan.proxy.jdkproxy.service.UserService;
import com.fanqiechaodan.proxy.jdkproxy.service.impl.UserServiceImpl;
import com.fanqiechaodan.proxy.jdkproxy.utils.ProxyUtil;

import java.util.UUID;

/**
 * @author fanqiechaodan
 * @Classname ProxyDemo
 * @Description {https://blog.csdn.net/qq_43135259/article/details/129364540?spm=1001.2014.3001.5502}
 */
public class ProxyDemo {

    public static void main(String[] args) throws InterruptedException {
/*        BigStar bigStar = new BigStar("陈奕迅");
        *//**
         * @param loader 指定一个类加载器
         * @param interfaces 指定生成的代理长什么样子,都有什么方法
         * @param h 指定生成的代理对象来干什么事情
         * @return 代理对象
         *//*
        Star star = (Star) Proxy.newProxyInstance(ProxyUtil.class.getClassLoader(), new Class[]{Star.class}, (proxy, method, args1) -> {
            if ("sing".equals(method.getName())) {
                System.out.println("准备话筒,收钱20W");
            } else if ("dance".equals(method.getName())) {
                System.out.println("准备场地,收钱100W");
            }
            return method.invoke(bigStar, args1);
        });
        String sing = star.sing("孤勇者");
        System.out.println(sing);
        star.dance();*/
        UserServiceImpl service = new UserServiceImpl();
        UserService proxy = ProxyUtil.createProxy(service);
        proxy.deleteUser(UUID.randomUUID().toString().replaceAll("-",""));
        proxy.login(UUID.randomUUID().toString().replaceAll("-",""),UUID.randomUUID().toString().replaceAll("-",""));
        proxy.selectUser();
    }

}
